/**
 *
 * @author 
 *
 */
class MapTools {
	public constructor() {
	}
	
    public static getLocalByPoint(sourcePt: egret.Point): egret.Point
    {
        return MapTools.getLocalByXY(sourcePt.x, sourcePt.y);
    }
    
    public static getLogicByPoint(sourcePt: egret.Point): egret.Point
    {
        return MapTools.getLogicByXY(sourcePt.x, sourcePt.y);
    }
    
    public static getLocalByXY(tx:number, ty:number):egret.Point
	{
	    var pt:egret.Point = new egret.Point();
	    pt.setTo(tx * Gconst.MAP_ITEM_W >> 0, ty * Gconst.MAP_ITEM_H >> 0);
	    return pt;    
	}
	
    public static getLogicByXY(tx: number, ty: number): egret.Point
    {
        var pt: egret.Point = new egret.Point();
        pt.setTo((tx / Gconst.MAP_ITEM_W) >> 0, (ty / Gconst.MAP_ITEM_H)>> 0);
        return pt;
    }
    
    public static getAngle(p1x: number, p1y: number, p2x: number, p2y: number, isAngle: Boolean = true): number
    {
        var dx: number = (p2x - p1x);
        var dy: number = (p2y - p1y);
        var newRadian: number = Math.atan2(dy, dx);
        var at: number = (newRadian * 180) / Math.PI;
        if(isAngle)
        {
            return at;
        };
        return newRadian;
    }

    public static angleToArpgDir(angle: number, directionNum: number = 8): number
    {
        angle = (angle % 360);
        if(angle < 0)
        {
            angle = (360 + angle);
        };
        var newDir: number = Math.round(angle / (360 / directionNum));
        if(newDir >= 6)
        {
            newDir = (newDir - 6);
        } else 
        {
            newDir = (newDir + 2);
        };
        if(newDir == directionNum)
        {
            newDir = 0;
        };
        return newDir;
    }

}
